﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace library
{
    public partial class lose_information : Form
    {
        public MySqlConnection conn = new DBclass().getConn();
        public lose_information()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            conn.Open();
            string sql = "select bID as 图书编号,uname as 申请人,app_time as 申请时间,app_reason as 申请理由,pay_status as 审核状态 from pay_info";
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            MySqlDataAdapter sd = new MySqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            sd.Fill(ds, "pay_info");
            dataGridView4.DataSource = ds;
            dataGridView4.DataMember = "pay_info";
            conn.Close();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (dataGridView4.Rows.Count > 0)
            {
                dataGridView4.EndEdit();//停止编辑状态
                foreach (DataGridViewRow row in dataGridView4.Rows)
                {
                    row.Cells[0].Value = true;
                }
            }
            conn.Open();
            if (dataGridView4.Rows.Count > 0)
            {
                int j = 0;
                for (int i = 0; i < dataGridView4.Rows.Count; i++)
                {
                    string bID = dataGridView4.Rows[0].Cells[0].Value.ToString();
                    string sql = "update pay_info set pay_status='已通过' where bID=@bID";
                    MySqlCommand cmd = new MySqlCommand(sql, conn);
                    cmd.Parameters.Add("@bID", MySqlDbType.Int32).Value = bID;
                    int num = cmd.ExecuteNonQuery();
                    if (num > 0)
                    {
                        MessageBox.Show("修改成功");
                    }
                        string sql1 = "update book_info set lose_whether='否' where bID=@bID";
                        MySqlCommand cmd1 = new MySqlCommand(sql1, conn);
                        cmd1.Parameters.Add("@bID", MySqlDbType.Int32).Value = bID;
                        //j += cmd.ExecuteNonQuery();
                        int num1 = cmd1.ExecuteNonQuery();
                        if (num1 > 0)
                        {
                            MessageBox.Show("修改成功");
                        }
                }
                if (j > 0)
                {
                    MessageBox.Show("修改成功");
                }
            }
            conn.Close();
            //this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            conn.Open();
            string sql = "select bID as 图书编号,uname as 申请人,app_time as 申请时间,app_reason as 申请理由,pay_status as 审核状态 from pay_info where pay_status='待审核'";
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            MySqlDataAdapter sd = new MySqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            sd.Fill(ds, "pay_info");
            dataGridView4.DataSource = ds;
            dataGridView4.DataMember = "pay_info";
            conn.Close();
        }
    }
}
